package edu.dlnu.gifttalk.welcome;

import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import edu.dlnu.gifttalk.MainActivity;
import edu.dlnu.gifttalk.R;

/**
 * Created by Risky57 on 2017/6/27.
 */

public class WelcomeActivity extends AppCompatActivity {

    //定义倒计时
    private int count = 5;
    private TextView mTextSkip;
    private CountDownTimer mTimer;

    @Override
    protected void onCreate (@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        mTextSkip = (TextView) findViewById(R.id.text_skip);
//两个参数，1：定时器的总时长2：定时器的间隔时间
            //每隔一次间隔时间都会执行
        //2个参数，时长和间隔时间
        mTimer = new CountDownTimer(count * 1000 + 500, 1000) {
            //每隔一次间隔时间执行
            @Override
            public void onTick (long millisUntilFinished) {
                mTextSkip.setText(count-- + "秒");
            }

            //显示
            @Override
            public void onFinish () {
                toMainActivity();
            }
        };
        //开启定时器
        mTimer.start();

    }
  //显示倒计时的Testview点击事件，
    public void onSkip (View view) {
        //取消倒计时
        mTimer.cancel();
        //跳转到
        toMainActivity();
    }

    private void toMainActivity(){
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }

}
